﻿Imports BUS
Imports DTO
Imports System.IO
Imports System.Data.OleDb

Public Class frmChinh
    '
    Private _tenNhanVien As String
    Public Property TenNhanVien() As String
        Get
            Return _tenNhanVien
        End Get
        Set(ByVal value As String)
            _tenNhanVien = value
        End Set
    End Property
    'TiepNhan
    Dim uscTiepNhanSo As UserControlTiepNhanSo
    Dim uscPhieuGuiTien As UserControlPhieuGuiTien
    Dim uscPhieuRutTien As UserControlPhieuRutTien
    Dim uscTiepNhanNhanVien As UserControlTiepNhanNhanVien
    Dim uscTiepNhanLoaiTietKiem As UserControlThemLoaiTietKiem
    ''

    'TraCuu
    Dim uscTraCuuSo As UserControlTraCuuSo
    Dim uscTraCuuPhieuGui As UserControlTraCuuPhieuGui
    Dim uscTraCuuPhieuRut As UserControlTraCuuPhieuRut
    Dim uscTraCuuKhachHang As UserControlTraCuuKhachHang

    'CapNhat
    Dim uscCapNhatSoTietKiem As UserControlCapNhatSoTietKiem
    Dim uscCapNhatPhieuGuiTien As UserControlCapNhatPhieuGuiTien
    Dim uscCapNhatPhieuRutTien As UserControlCapNhatPhieuRutTien
    Dim uscCapNhatNhanVien As UserControlCapNhatNhanVien
    Dim uscCapNhatLoaiTietKiem As UserControlCapNhatLoaiTietKiem

    'Luu Tru
    Dim uscImPort As UserControlImport
    Dim uscExPort As UserControlExport
    Dim uscSaoLuPhucHoi As UserControlSaoLuuPhucHoi

    'Xoa
    Dim uscXoaSoTietKiem As UserControlXoaSoTietKiem
    Dim uscXoaLoaiTietKiem As UserControlXoaLoaiTietKiem
    Dim uscXoaNhanVien As UserControlXoaNhanVien

    'Xem Danh SAch
    Dim uscXemDanhSachNhanVien As New UserControlXemDanhSachNhanVien
    Dim uscXemDanhSachLoaiTietKiem As New UserControlXemDanhSachLoaiTietKiem
    Dim uscXemDanhSachSoTietKiem As New UserControlXemDanhSachSoTietKiem
    Dim uscXemDanhSachPhieuGuiTien As New UserControlXemDanhSachPhieuGui
    Dim uscXemDanhSachPhieuRut As New UserControlXemDanhSachPhieuRut


    Public Property UscTraCuuSoProperty() As UserControlTraCuuSo
        Get
            Return uscTraCuuSo
        End Get
        Set(ByVal value As UserControlTraCuuSo)
            uscTraCuuSo = value
        End Set
    End Property
    Public Property UscTraCuuPhieuGuiProperty() As UserControlTraCuuPhieuGui
        Get
            Return uscTraCuuPhieuGui
        End Get
        Set(ByVal value As UserControlTraCuuPhieuGui)
            uscTraCuuPhieuGui = value
        End Set
    End Property

    Public Property UscTraCuuPhieuRutProperty() As UserControlTraCuuPhieuRut
        Get
            Return uscTraCuuPhieuRut
        End Get
        Set(ByVal value As UserControlTraCuuPhieuRut)
            uscTraCuuPhieuRut = value
        End Set
    End Property

    Public Property UscTraCuuKhachHangProperty() As UserControlTraCuuKhachHang
        Get
            Return uscTraCuuKhachHang
        End Get
        Set(ByVal value As UserControlTraCuuKhachHang)
            uscTraCuuKhachHang = value
        End Set
    End Property
    '''
    ''' 

    Private Sub frmChinh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        'So Tiet Kiem
        tabTiepNhan.Enabled = False
        tabBaoCao.Enabled = False
        tabCapNhat.Enabled = False
        tabTraCuu.Enabled = False
        tabLuuTruu.Enabled = False
        tabXemDanhSach.Enabled = False
        tabXoa.Enabled = False
        LoadConTrolTabTiepNhan()
        'Tra cuu so
        LoadConTrolTabTraCuu()
        LoadConTrolTabCapNhat()
        LoadConTrolTabLuuTru()
        LoadControlTabXoa()
        LoadControlXemDanhSach()
        'Xu ly bang Thong ke
        'Timer1.Start()



       

    End Sub
    Private Sub LoadConTrolTabTiepNhan()
        uscTiepNhanSo = New UserControlTiepNhanSo()
        uscTiepNhanSo.Location = New Point(0, 40)
        tabTiepNhan.Controls.Add(uscTiepNhanSo)
        uscPhieuGuiTien = New UserControlPhieuGuiTien()
        uscPhieuGuiTien.Location = New Point(0, 40)
        tabTiepNhan.Controls.Add(uscPhieuGuiTien)
        uscPhieuRutTien = New UserControlPhieuRutTien()
        uscPhieuRutTien.Location = New Point(0, 40)
        tabTiepNhan.Controls.Add(uscPhieuRutTien)
        uscTiepNhanNhanVien = New UserControlTiepNhanNhanVien()
        uscTiepNhanNhanVien.Location = New Point(0, 40)
        tabTiepNhan.Controls.Add(uscTiepNhanNhanVien)
        uscTiepNhanLoaiTietKiem = New UserControlThemLoaiTietKiem()
        uscTiepNhanLoaiTietKiem.Location = New Point(0, 40)
        tabTiepNhan.Controls.Add(uscTiepNhanLoaiTietKiem)

    End Sub

    Private Sub LoadConTrolTabTraCuu()
        uscTraCuuSo = New UserControlTraCuuSo()
        uscTraCuuSo.Location = New Point(0, 40)
        tabTraCuu.Controls.Add(uscTraCuuSo)
        uscTraCuuPhieuGui = New UserControlTraCuuPhieuGui()
        uscTraCuuPhieuGui.Location = New Point(0, 40)
        uscTraCuuPhieuGui.Visible = False
        tabTraCuu.Controls.Add(uscTraCuuPhieuGui)
        uscTraCuuPhieuRut = New UserControlTraCuuPhieuRut()
        uscTraCuuPhieuRut.Location = New Point(0, 40)
        uscTraCuuPhieuRut.Visible = False
        tabTraCuu.Controls.Add(uscTraCuuPhieuRut)

        uscTraCuuKhachHang = New UserControlTraCuuKhachHang()
        uscTraCuuKhachHang.Location = New Point(0, 40)
        uscTraCuuKhachHang.Visible = False
        tabTraCuu.Controls.Add(uscTraCuuKhachHang)

    End Sub

    Private Sub LoadConTrolTabCapNhat()
        uscCapNhatSoTietKiem = New UserControlCapNhatSoTietKiem()
        uscCapNhatSoTietKiem.Location = New Point(0, 40)
        tabCapNhat.Controls.Add(uscCapNhatSoTietKiem)

        uscCapNhatPhieuGuiTien = New UserControlCapNhatPhieuGuiTien()
        uscCapNhatPhieuGuiTien.Location = New Point(0, 40)
        uscCapNhatPhieuGuiTien.Visible = False
        tabCapNhat.Controls.Add(uscCapNhatPhieuGuiTien)

        uscCapNhatPhieuRutTien = New UserControlCapNhatPhieuRutTien()
        uscCapNhatPhieuRutTien.Location = New Point(0, 40)
        uscCapNhatPhieuRutTien.Visible = False
        tabCapNhat.Controls.Add(uscCapNhatPhieuRutTien)

        uscCapNhatNhanVien = New UserControlCapNhatNhanVien()
        uscCapNhatNhanVien.Location = New Point(0, 40)
        uscCapNhatNhanVien.Visible = False
        tabCapNhat.Controls.Add(uscCapNhatNhanVien)

        uscCapNhatLoaiTietKiem = New UserControlCapNhatLoaiTietKiem()
        uscCapNhatLoaiTietKiem.Location = New Point(0, 40)
        uscCapNhatLoaiTietKiem.Visible = False
        tabCapNhat.Controls.Add(uscCapNhatLoaiTietKiem)


    End Sub

    Private Sub LoadConTrolTabLuuTru()
        uscImPort = New UserControlImport()
        uscImPort.Location = New Point(0, 40)
        tabLuuTruu.Controls.Add(uscImPort)
        uscExPort = New UserControlExport()
        uscExPort.Location = New Point(0, 40)
        tabLuuTruu.Controls.Add(uscExPort)
        uscSaoLuPhucHoi = New UserControlSaoLuuPhucHoi()
        uscSaoLuPhucHoi.Location = New Point(0, 40)
        uscSaoLuPhucHoi.Visible = False
        tabLuuTruu.Controls.Add(uscSaoLuPhucHoi)
    End Sub

    Private Sub LoadControlTabXoa()
        uscXoaSoTietKiem = New UserControlXoaSoTietKiem()
        uscXoaSoTietKiem.Location = New Point(0, 40)
        tabXoa.Controls.Add(uscXoaSoTietKiem)

        uscXoaLoaiTietKiem = New UserControlXoaLoaiTietKiem()
        uscXoaLoaiTietKiem.Location = New Point(0, 40)
        uscXoaLoaiTietKiem.Visible = False
        tabXoa.Controls.Add(uscXoaLoaiTietKiem)

        uscXoaNhanVien = New UserControlXoaNhanVien()
        uscXoaNhanVien.Location = New Point(0, 40)
        uscXoaNhanVien.Visible = False
        tabXoa.Controls.Add(uscXoaNhanVien)
    End Sub

    Private Sub LoadControlXemDanhSach()
        uscXemDanhSachNhanVien.Visible = False
        uscXemDanhSachNhanVien.Location = New Point(0, 40)
        tabXemDanhSach.Controls.Add(uscXemDanhSachNhanVien)
        uscXemDanhSachLoaiTietKiem.Visible = False
        uscXemDanhSachLoaiTietKiem.Location = New Point(0, 40)
        tabXemDanhSach.Controls.Add(uscXemDanhSachLoaiTietKiem)
        uscXemDanhSachSoTietKiem.Visible = False
        uscXemDanhSachSoTietKiem.Location = New Point(0, 40)
        tabXemDanhSach.Controls.Add(uscXemDanhSachSoTietKiem)
        uscXemDanhSachPhieuGuiTien.Visible = False
        uscXemDanhSachPhieuGuiTien.Location = New Point(0, 40)
        tabXemDanhSach.Controls.Add(uscXemDanhSachPhieuGuiTien)
        uscXemDanhSachPhieuRut.Visible = False
        uscXemDanhSachPhieuRut.Location = New Point(0, 40)
        tabXemDanhSach.Controls.Add(uscXemDanhSachPhieuRut)
    End Sub

    Private Sub btnMoSo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoSo.Click
        uscTiepNhanSo.Visible = True
        uscPhieuRutTien.Visible = False
        uscPhieuGuiTien.Visible = False
        uscTiepNhanNhanVien.Visible = False
        uscTiepNhanLoaiTietKiem.Visible = False
    End Sub

    Private Sub btnGuiTien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuiTien.Click

        uscTiepNhanSo.Visible = False
        uscPhieuRutTien.Visible = False
        uscPhieuGuiTien.Visible = True
        uscTiepNhanNhanVien.Visible = False
        uscTiepNhanLoaiTietKiem.Visible = False

    End Sub

    Private Sub btnRutTien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRutTien.Click
        uscPhieuRutTien.Visible = True
        uscPhieuGuiTien.Visible = False
        uscTiepNhanSo.Visible = False
        uscTiepNhanNhanVien.Visible = False
        uscTiepNhanLoaiTietKiem.Visible = False

    End Sub

    Private Sub btnTiepNhanNhanVien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTiepNhanNhanVien.Click
        uscPhieuRutTien.Visible = False
        uscPhieuGuiTien.Visible = False
        uscTiepNhanSo.Visible = False
        uscTiepNhanNhanVien.Visible = True
        uscTiepNhanLoaiTietKiem.Visible = False
    End Sub

    Private Sub btnLoaiTietKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoaiTietKiem.Click
        uscPhieuRutTien.Visible = False
        uscPhieuGuiTien.Visible = False
        uscTiepNhanSo.Visible = False
        uscTiepNhanNhanVien.Visible = False
        uscTiepNhanLoaiTietKiem.Visible = True
    End Sub

    Private Sub TraCuuSo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTraCuuSo.Click
        uscTraCuuSo.Visible = True
        uscTraCuuPhieuGui.Visible = False
        uscTraCuuPhieuRut.Visible = False
        uscTraCuuKhachHang.Visible = False

    End Sub

    Private Sub btnDanhSachPhieuGUi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDanhSachPhieuGUi.Click
        uscTraCuuPhieuGui.Visible = True
        uscTraCuuSo.Visible = False
        uscTraCuuPhieuRut.Visible = False
        uscTraCuuKhachHang.Visible = False


    End Sub

    Private Sub btnDanhSachPhieuRut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDanhSachPhieuRut.Click
        uscTraCuuPhieuRut.Visible = True
        uscTraCuuSo.Visible = False
        uscTraCuuPhieuGui.Visible = False
        uscTraCuuKhachHang.Visible = False

    End Sub


    Dim i As Integer = 0
    Dim dsLoaiTietKiem As New List(Of LoaiTietKiemDTO)()


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        i += 1
        dsLoaiTietKiem = LoaiTietKiemBUS.LayLoaiTietKiem()
        If dsLoaiTietKiem(i).MaLoaiTietKiem > 0 Then
            Dim str As String = dsLoaiTietKiem(i).TenLoaiTietKiem + " : "
            Dim SizeX As Integer = str.Length * 6
            lblLoaiTietKiem.Size = New Size(SizeX, 15)
            lblLoaiTietKiem.Text = str
            lblLaiSuat.Location = New Point(lblLoaiTietKiem.Location.X + SizeX, 12)
            lblLaiSuat.Text = dsLoaiTietKiem(i).LaiSuat.ToString + "%"
            If i = dsLoaiTietKiem.Count - 2 Then
                i = -1
            End If

        End If
        Me.Invalidate()
    End Sub

    Private Sub btnKhachHang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKhachHang.Click
        uscTraCuuKhachHang.Visible = True
        uscTraCuuPhieuGui.Visible = False
        uscTraCuuSo.Visible = False
        uscTraCuuPhieuRut.Visible = False
    End Sub

    Private Sub btnCapNhatSoTietKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhatSoTietKiem.Click
        uscCapNhatSoTietKiem.Visible = True
        uscCapNhatPhieuRutTien.Visible = False
        uscCapNhatPhieuGuiTien.Visible = False
    End Sub

    Private Sub btnCapNhatPhieuGuiTien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhatPhieuGuiTien.Click
        uscCapNhatSoTietKiem.Visible = False
        uscCapNhatPhieuRutTien.Visible = False
        uscCapNhatPhieuGuiTien.Visible = True
    End Sub

    Private Sub btnCapNhatPhieuRutTien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhatPhieuRutTien.Click
        uscCapNhatSoTietKiem.Visible = False
        uscCapNhatPhieuRutTien.Visible = True
        uscCapNhatPhieuGuiTien.Visible = False
    End Sub

    Private Sub btnCapNhatNhanVien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhatNhanVien.Click
        uscCapNhatSoTietKiem.Visible = False
        uscCapNhatPhieuRutTien.Visible = False
        uscCapNhatPhieuGuiTien.Visible = False
        uscCapNhatNhanVien.Visible = True
        uscCapNhatLoaiTietKiem.Visible = False
    End Sub

    Private Sub btnCapNhatLoaiTietKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhatLoaiTietKiem.Click
        uscCapNhatSoTietKiem.Visible = False
        uscCapNhatPhieuRutTien.Visible = False
        uscCapNhatPhieuGuiTien.Visible = False
        uscCapNhatNhanVien.Visible = False
        uscCapNhatLoaiTietKiem.Visible = True
    End Sub

    Private Sub btnCapNhatThamSo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhatThamSo.Click

    End Sub

    Private Sub btnSaoLuuPhucHoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaoLuuPhucHoi.Click
        uscExPort.Visible = False
        uscSaoLuPhucHoi.Visible = True
        uscImPort.Visible = False
    End Sub

    Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
        uscExPort.Visible = True
        uscSaoLuPhucHoi.Visible = False
        uscImPort.Visible = False
    End Sub

    Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click
        uscExPort.Visible = False
        uscSaoLuPhucHoi.Visible = False
        uscImPort.Visible = True
    End Sub


    Private Sub btnDangNhap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDangNhap.Click
        'Dim frm As New frmDangNhap()
        'frm.ShowDialog()
        'If frm.FlagProperty = True Then
        '        _tenNhanVien = frm.NvienDToProperty.TenNhanVien
        ' lblTenNhanVien.Text = _tenNhanVien.ToString()
        tabTiepNhan.Enabled = True
        tabBaoCao.Enabled = True
        tabCapNhat.Enabled = True
        tabTraCuu.Enabled = True
        tabLuuTruu.Enabled = True
        tabXemDanhSach.Enabled = True
        tabXoa.Enabled = True
        'End If
    End Sub

    Private Sub btnDoanhSo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoanhSo.Click
        Dim frm As New frmBaoCaoDoanhSo()
        frm.TenNhanVien = _tenNhanVien
        frm.Show()
    End Sub


    Private Sub btnXoaSoTietKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaSoTietKiem.Click
        uscXoaSoTietKiem.Visible = True
        uscXoaLoaiTietKiem.Visible = False
        uscXoaNhanVien.Visible = False
    End Sub

    Private Sub btnXoaLoaiTietKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaLoaiTietKiem.Click
        uscXoaSoTietKiem.Visible = False
        uscXoaLoaiTietKiem.Visible = True
        uscXoaNhanVien.Visible = False
    End Sub

    Private Sub btnXoaNhanVien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaNhanVien.Click
        uscXoaSoTietKiem.Visible = False
        uscXoaLoaiTietKiem.Visible = False
        uscXoaNhanVien.Visible = True
    End Sub
    Dim _logan As Integer = 0
    Dim _flagLogan As Boolean = False
    Dim dem As Integer = 0
    Dim dem1 As Integer = 0
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        _logan += 1
        dem += 1
        dem1 += 1
        If _logan = 1 Then
            lblLogan.ForeColor = Color.Green
        End If
        If _logan = 2 Then
            lblLogan.ForeColor = Color.Violet
        End If
        If _logan = 3 Then
            lblLogan.ForeColor = Color.Tomato
        End If
        If _logan = 4 Then
            lblLogan.ForeColor = Color.HotPink
            _flagLogan = False
            _logan = 0

        End If
        If dem = 4 And dem1 = 4 Then
            Timer2.Interval = 60
            dem1 = 0
        End If
        If dem1 = 40 Then
            Timer2.Interval = 1500
            dem = 0
            dem1 = 0
        End If

    End Sub

    Private Sub btnBaoCaoMoSo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBaoCaoMoSo.Click
        Dim frm As New frmBaoCaoMoDongSoThang()
        frm.TenNhanVien = _tenNhanVien
        frm.Show()
    End Sub

    
  
    Private Sub btnXemDanhSachNhanVien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXemDanhSachNhanVien.Click
        uscXemDanhSachNhanVien.Visible = True
        uscXemDanhSachLoaiTietKiem.Visible = False
        uscXemDanhSachPhieuGuiTien.Visible = False
        uscXemDanhSachPhieuRut.Visible = False
        uscXemDanhSachSoTietKiem.Visible = False
    End Sub

    Private Sub btnXemDanhSachLoaiTietKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXemDanhSachLoaiTietKiem.Click
        uscXemDanhSachNhanVien.Visible = False
        uscXemDanhSachLoaiTietKiem.Visible = True
        uscXemDanhSachPhieuGuiTien.Visible = False
        uscXemDanhSachPhieuRut.Visible = False
        uscXemDanhSachSoTietKiem.Visible = False
    End Sub

    Private Sub btnXemDanhSachSoTietKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXemDanhSachSoTietKiem.Click
        uscXemDanhSachNhanVien.Visible = False
        uscXemDanhSachLoaiTietKiem.Visible = False
        uscXemDanhSachPhieuGuiTien.Visible = False
        uscXemDanhSachPhieuRut.Visible = False
        uscXemDanhSachSoTietKiem.Visible = True
    End Sub

    Private Sub btnPhieuGuiTien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPhieuGuiTien.Click
        uscXemDanhSachNhanVien.Visible = False
        uscXemDanhSachLoaiTietKiem.Visible = False
        uscXemDanhSachPhieuGuiTien.Visible = True
        uscXemDanhSachPhieuRut.Visible = False
        uscXemDanhSachSoTietKiem.Visible = False
    End Sub

    Private Sub btnPhieuRutTien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPhieuRutTien.Click
        uscXemDanhSachNhanVien.Visible = False
        uscXemDanhSachLoaiTietKiem.Visible = False
        uscXemDanhSachPhieuGuiTien.Visible = False
        uscXemDanhSachPhieuRut.Visible = True
        uscXemDanhSachSoTietKiem.Visible = False
    End Sub
End Class